<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('公共课程详情列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>名称：</label>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <label>类型：</label>
                            <select name="typeName" class="form-control m-b"  th:with="type=${@dict.getType('course_categoryType')}">
                                <option  value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" >
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" >
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" >
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:coursePackageV2:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:coursePackageV2:remove')}]];
    var prefix = ctx + "system/coursePackageV2";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "公共课程详情",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'id',
                },

                {
                    field: 'name',
                    title: '名称'
                },

                {
                    field: 'tags',
                    title: '标签'
                },
                {
                    field: 'typeName',
                    title: '类型名称',
                    formatter: function(value, item, index) {
                        return typeName(item.typeName);
                    }
                },
                {
                    field: 'orderNum',
                    title: '显示顺序'
                },
                {
                    field: 'createdName',
                    title: '创建人名称'
                },
                {
                    field: 'created',
                    title: '创建时间'
                },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs  " href="javascript:void(0)" onclick="copyStructure(\'' + row.id + '\')"></i>复制</a> ');
                        actions.push('<a class="btn label-primary btn-xs  " href="javascript:void(0)" onclick="relationList(\'' + row.id + '\')"></i>关联列表</a> ');
                        actions.push('<a class="btn btn-warning btn-xs  " href="javascript:void(0)" onclick="timeContentList(\'' + row.id + '\')"></i>详情</a> ');
                        actions.push('<a class="btn label-primary btn-xs  " href="javascript:void(0)" onclick="copyCourse(\'' + row.id + '\')"></i>关联到教保指引</a> ');
                        // actions.push('<a class="btn btn-warning btn-xs  " href="javascript:void(0)" onclick="copyCourse(\'' + row.id + '\')"></i>拷贝到教保指引</a> ');
                        actions.push('<a class="btn btn-success btn-xs  " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs  " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    function typeName(typeName) {
        if (typeName==null || typeName ==undefined || typeName==''){
            return '';
        }
        var type  = typeName.split(',');
        var content = "";
        for (let i = 0; i < type.length; i++) {
            if (type[i] == "1") {
                content += '<span class="label label-success">全书同</span>';
            } else if (type[i] == '2') {
                content += '<span class="label label-primary">全月龄同</span>';
            } else if (type[i] == '3') {
                content += '<span class="label label-warning">全周同</span>';
            }
        }
        return content;
    }


    function copyStructure(id) {
        $.modal.confirm("确认要复制数据吗?", function() {
            var url = '/system/course/copyStructure?id=' + id;
            $.operate.submit(url, "post", "json", "");
        });
    }

    function timeContentList(id) {
        var url = '/system/courseContent/coursePackageList?packageId=' + id;
        $.modal.openTab(" 详情", url);
    }

    function copyCourse(id) {
        var url = '/system/course/copyCoursePackagesV2?id=' + id;
        $.modal.open("选择需要拷贝到的课程", url);
    }

    function relationList(id) {
        var url = '/system/vendorCourseRelPackagev2/packageV2Id?packageV2Id=' + id;
        $.modal.openTab("关联课程列表", url);
    }

</script>
</body>
</html>